//
//  HCUserAccount.swift
//  Hweibome
//
//  Created by 何川 on 15/12/8.
//  Copyright © 2015年 hechuan. All rights reserved.
//

import UIKit

class HCUserAccount: NSObject ,NSCoding {

    var uid:String?
    var expires_in: NSTimeInterval = 0 {
        
        didSet{
            //requre expires-in
           // expiresDate = NSDate( timeIntervalSinceNow：expires_in)
            expiresDate = NSDate( timeIntervalSinceNow : expires_in)
           // printLog(expiresDate)
            // + expires_in 还有一种方式进行，是调整expires-in类型
        }
    }
    
    //access-token +expires-in

    var expiresDate: NSDate?
    
    
    var access_token: String?
    
    var avatar_large: String?
    
    var screen_name : String?
    
    init(dict:[String:AnyObject])
    {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    //为了避免key不对应问题
    }
    override var description: String
        {
        let keys = ["uid","expires_in","access_token","avatar_large","screen_name"]
            return dictionaryWithValuesForKeys(keys).description
    }
    
    //解档，从文件读对象
    required  init(coder aDecoder: NSCoder)
    {
        uid = aDecoder.decodeObjectForKey("uid") as? String
        expiresDate = aDecoder.decodeObjectForKey("expiresDate") as? NSDate
        avatar_large = aDecoder.decodeObjectForKey("avatar_large") as? String
        screen_name = aDecoder.decodeObjectForKey("screen_name") as? String
        access_token = aDecoder.decodeObjectForKey("access_token") as? String

    }
    //归档，把对象保存成二进制文件
     func encodeWithCoder(aCoder: NSCoder)
     {
        aCoder.encodeObject(uid, forKey: "uid")
         aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeObject(avatar_large, forKey: "avatar_large")
        aCoder.encodeObject(screen_name, forKey: "screen_name")
        aCoder.encodeObject(expiresDate, forKey: "expiresDate")



    }

}


























